package ag.script.project.standard.core;

import cn.hutool.core.io.FileUtil;

import java.io.File;

public class ScriptProjectStandardLog {
    private String projectPath;
    private File logFile;

    public ScriptProjectStandardLog(String projectPath) {
        this.projectPath = projectPath;
        if (FileUtil.exist(projectPath)) {
            logFile = new File(projectPath, "ag-script-standard.log");
        }
    }

    public void log(Object... msg) {
        if (!FileUtil.exist(projectPath)) {
            throw new RuntimeException(" projectPath is not exits!");
        }
        if (!FileUtil.isDirectory(projectPath)) {
            throw new RuntimeException(" projectPath is must a directory!");
        }
        StringBuilder sb = new StringBuilder();
        for (Object s : msg) {
            if (s == null) {
                continue;
            }
            sb.append(s).append("\t");
        }
        FileUtil.appendUtf8String(sb.append("\n\n").toString(), logFile);
    }

}
